package com.burst.reptile.framework.upload;

import org.apache.commons.fileupload.ProgressListener;
import org.springframework.stereotype.Component;
 
import javax.servlet.http.HttpSession;

/**
 * 文件上传进度监听器
 * @author wujin
 *
 * @date: 2020年6月17日 下午10:13:29
 */
@Component
public class FileUploadProgressListener implements ProgressListener{

	private HttpSession session;
	 
    public void setSession(HttpSession session) {
        this.session = session;
        session.setAttribute("upload_percent", 0);
    }
 
    @Override
    public void update(long pBytesRead, long pContentLength, int pItems) {
        int percent = (int) (pBytesRead * 100.0 / pContentLength);
        session.setAttribute("upload_percent", percent);
    }
}
